//
//  ftext.swift
//  xzseller
//
//  Created by zhuxietong on 2021/1/27.
//

import Foundation
import Eelay



open class FText:FField,UITextFieldDelegate{
    public let node = MoDisplayNode { () -> UIView in
        let f = UITextField()
        return f
    }
    open var textField:UITextField{
        get{
            return node.view as! UITextField
        }
    }
    open override var valueDisplay:String{
        return "\(value)"
    }
    
    open override func updateDispaly() {
    }
    
    open override func didLoadProps() {
        textField.text = "\(value)"
        textField.ui.font(font: valueStyle.font).text(color: valueStyle.color)
    }
    
    open override func willLayoutRules() {
        super.willLayoutRules()
        textField.delegate = self
        textField.addTarget(self, action: #selector(changeValue), for: .editingChanged)
    }
    
    open func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    
    @objc open func changeValue(){
        update(value: textField.text ?? "", edit: .input)
    }
   
}

